<template>
  <div class="settings-container">
    <el-card class="settings-card">
      <template #header>
        <div class="card-header">
          <span>用户设置</span>
        </div>
      </template>

      <el-form :model="userSettings" label-width="120px">
        <el-form-item label="用户名">
          <el-input v-model="userSettings.username" disabled />
        </el-form-item>

        <el-form-item label="修改密码">
          <el-input v-model="userSettings.newPassword" type="password" placeholder="请输入新密码" />
        </el-form-item>

        <el-form-item label="确认密码">
          <el-input
            v-model="userSettings.confirmPassword"
            type="password"
            placeholder="请再次输入新密码"
          />
        </el-form-item>

        <el-form-item label="邮箱">
          <el-input v-model="userSettings.email" placeholder="请输入邮箱" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="handleSave">保存设置</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useUsernameStore } from '@/stores/usernameStore'

const usernameStore = useUsernameStore()

const userSettings = ref({
  username: usernameStore.username,
  newPassword: '',
  confirmPassword: '',
  email: '',
})

const handleSave = () => {
  if (userSettings.value.newPassword !== userSettings.value.confirmPassword) {
    ElMessage.error('两次输入的密码不一致')
    return
  }

  // 这里可以添加保存设置的逻辑
  ElMessage.success('设置保存成功')
}

const resetForm = () => {
  userSettings.value = {
    username: usernameStore.username,
    newPassword: '',
    confirmPassword: '',
    email: '',
  }
}
</script>

<style scoped>
.settings-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.settings-card {
  margin-top: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-form {
  margin-top: 20px;
}
</style>
